Provides a delegate that performs a test on key/value pair
Syntax
Parameters
- key
- original
Type Parameters
- TKey
- TValue
Example
BPlusTree/BPlusTree.Test/ThreadedBTreeTest.cs
C# | Copy Code |
---|
const int CountPerThread = 100;
BPlusTree<KeyInfo, DataValue>.OptionsV2 options = new BPlusTree<KeyInfo, DataValue>.OptionsV2(
new KeyInfoSerializer(), new DataValueSerializer(), new KeyInfoComparer());
options.CalcBTreeOrder(32, 300);
options.FileName = TempFile.TempPath;
options.CreateFile = CreatePolicy.Always;
using (BPlusTree<KeyInfo, DataValue> dictionary = new BPlusTree<KeyInfo, DataValue>(options))
using (WorkQueue work = new WorkQueue(Environment.ProcessorCount))
{
Exception lastError = null;
work.OnError += delegate(object o, ErrorEventArgs e) { lastError = e.GetException(); };
for (int i = 0; i < Environment.ProcessorCount; i++)
work.Enqueue(new ThreadedTest(dictionary, CountPerThread).Run);
for (int i = 0; i < CountPerThread; i++)
{
if(i%2 == 0)
{
try {
dictionary.TryAdd(new KeyInfo(Guid.NewGuid(), i), k => { throw new ExpectedException(); });
} catch { }
}
else
{
try
{
dictionary.TryRemove(dictionary.First().Key, (k, v) => { throw new ExpectedException(); });
}
catch { }
}
}
Assert.IsTrue(work.Complete(true, 60000));
Assert.IsNull(lastError, "Exception raised in worker: {0}", lastError);
} |
VB.NET | Copy Code |
---|
Const CountPerThread As Integer = 100
Dim options As New BPlusTree(Of KeyInfo, DataValue).OptionsV2(New KeyInfoSerializer(), New DataValueSerializer(), New KeyInfoComparer())
options.CalcBTreeOrder(32, 300)
options.FileName = TempFile.TempPath
options.CreateFile = CreatePolicy.Always
Using dictionary As New BPlusTree(Of KeyInfo, DataValue)(options)
Using work As New WorkQueue(Environment.ProcessorCount)
Dim lastError As Exception = Nothing
work.OnError += Function(o As Object, e As ErrorEventArgs) Do
lastError = e.GetException()
End Function
Dim i As Integer = 0
While i < Environment.ProcessorCount
work.Enqueue(New ThreadedTest(dictionary, CountPerThread).Run)
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
Dim i As Integer = 0
While i < CountPerThread
If i Mod 2 = 0 Then
Try
dictionary.TryAdd(New KeyInfo(Guid.NewGuid(), i), Function(k)
Throw New ExpectedException()
End Function)
Catch
End Try
Else
Try
dictionary.TryRemove(dictionary.First().Key, Function(k, v)
Throw New ExpectedException()
End Function)
Catch
End Try
End If
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
Assert.IsTrue(work.Complete(True, 60000))
Assert.IsNull(lastError, "Exception raised in worker: {0}", lastError)
End Using
End Using |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also